#pragma once

#include <string>
#include <map>

using namespace std;

namespace yazi{
namespace utility{

class Value{
public:
    Value();
    Value(bool value);
    Value(int value);
    Value(double value);
    Value(const char* value);
    Value(const string& value);

    Value& operator = (bool value);
    Value& operator = (int value);
    Value& operator = (double value);
    Value& operator = (const char* value);
    Value& operator = (const string& value); 

    operator bool();
    operator int();
    operator double();
    operator string();
    operator string() const;

private:
    string m_value;

};

typedef map<string, Value> Section;

class IniFile{
public:
    IniFile();

    bool load(const char* filename);
    bool load(const string& filename);

    string serial();
    void show();
    void save(const string& filename);

    bool has(const string& section);
    bool has(const string& section, const string& key);
    Value& get(const string& section, const string& key);
    void set(const string& section, const string& key, const Value& value);
    void remove(const string& section);
    void remove(const string& section, const string& key);
    void clear();

    Section& operator [] (const string& section) ;
private:
    string trim(const string& str);

private:
    string m_filename;
    map<string, Section> m_sections;
};


}}